package com.weixing.mall.provider.controller.admin;

import cn.hutool.core.util.ObjectUtil;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.auth.AuthUtil;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.provider.model.dto.NosuppllyOperationDto;
import com.weixing.mall.provider.model.vo.OrderOperationVo;
import com.weixing.mall.provider.service.IOrderOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单操作相关接口
 *
 * @author  gjq
 * @date  2019/10/15
 * @since  1.0
 **/
@RestController
@RequestMapping("orderOperation")
public class OrderOperationController {

    @Autowired
    private IOrderOperationService orderOperationService;


    /**
     * 加载订单操作列表
     * @param orderId 订单id
     * @return 订单操作列表
     */
    @GetMapping("getOrderOperation/{orderId}")
    public Result<List<OrderOperationVo>> getOrderList(@PathVariable Long orderId) {
        List<OrderOperationVo> list = orderOperationService.selectList(orderId);
        return ResultUtil.success(list);
    }


    /**
     * 断货订单保存操作及记录断货审核状态和时间
     *
     * @param dto 操作内容
     * @return 结果
     */
    @PostMapping("nosuppllyOperationSave")
    @NoRepeatSubmit
    public Result nosuppllyOperationSave( @Validated NosuppllyOperationDto dto) {
        SysAuth auth = AuthUtil.getSysExt();
        orderOperationService.nosuppllyOperationSave(dto,auth);
        return ResultUtil.success();
    }

    /**
     * 断货订单保存操作及记录断货审核状态和时间
     * @param dto 参数
     * @return 结果
     */
    @PostMapping("nosuppllyOperationSaveBatch")
    @NoRepeatSubmit
    public Result nosuppllyOperationSaveBatch( @Validated NosuppllyOperationDto dto) {
        SysAuth auth = AuthUtil.getSysExt();
        if(ObjectUtil.isNotEmpty(dto) && dto.getIds()!=null){
          for (Long id:dto.getIds()){
              dto.setOrderId(id);
              orderOperationService.nosuppllyOperationSave(dto,auth);
          }
            return ResultUtil.success();
        }
        return ResultUtil.error();
    }
}
